package com.cl.security.core.entity;

import com.cl.security.base.entity.BaseEntity;
import com.cl.security.base.entity.TreeEntity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "mall_category")
@Getter
@Setter
@SQLDelete(sql = "update mall_category set deleted=1 where id=?")
@Where(clause = "deleted<>1")
public class Category extends TreeEntity<Category> {
    @OneToMany(mappedBy = "category",cascade = CascadeType.ALL)
    private Set<Product> products = new HashSet<>();

    @OneToMany(mappedBy = "category",cascade = CascadeType.ALL,orphanRemoval = true)
//    @JoinTable(name = "mall_category_property",joinColumns = @JoinColumn(name = "category_id"),inverseJoinColumns = @JoinColumn(name = "property_id"))
    @OrderBy("id")
    private Set<Property> properties = new HashSet<>();
}
